﻿Public Class ReplaceImageCommand
    Inherits CommandBase
    Private _imagepath As String
    Private _copypath As String
    Private previousfile As Byte()
    Public Sub New(ByVal ImagePath As String, ByVal CopyPath As String)
        Me._imagepath = ImagePath
        Me._copypath = CopyPath
    End Sub
    Friend Overrides Sub Execute()
        If File.Exists(_imagepath) Then
            previousfile = File.ReadAllBytes(_imagepath)
        End If
        File.Copy(_copypath, _imagepath, True)
        onImagingChanged(Me, New ImagingChangedEventArgs(_imagepath))
    End Sub
    Friend Overrides Sub Undo()
        If previousfile IsNot Nothing Then
            File.WriteAllBytes(_imagepath, previousfile)
        Else
            File.Delete(_imagepath)
        End If
        onImagingChanged(Me, New ImagingChangedEventArgs(_imagepath))
    End Sub
End Class